package com.ftg.learn.util;

import lombok.Data;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author 布衣
 */
@Data
public class R<E> {
    private Integer code;

    private String msg;

    private E data;

    public static <E> R<E> ok(E data) {
        return build(200, "success", data);
    }

    public static <E> R<E> build(Integer code, String msg, E data) {
        R<E> r = new R<>();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);
        return r;
    }
    public static <E> R<E> build(TipUtil tu) {
        R<E> r = new R<>();
        r.setCode(tu.getCode());
        r.setMsg(tu.getMsg());
        return r;
    }
    public static <E> R<E> build(TipUtil tu, String msg) {
        R<E> r = new R<>();
        r.setCode(tu.getCode());
        r.setMsg(tu.getMsg() + msg);
        return r;
    }

    public static <E> R<E> build(TipUtil tu, E data) {
        R<E> r = new R<>();
        r.setCode(tu.getCode());
        r.setMsg(tu.getMsg());
        r.setData(data);
        return r;
    }

}
